import show_modal from './show_modal.js'
 
const showModal = {
	install: function(Vue) {
        const show_modal_fun=function(op={}){
			//#ifdef APP-PLUS
			return	new Promise((resolve, reject)=>{
			   let ssm= new show_modal({
					...op,
					$event:function(e){
						if(e.res){
							resolve(e)
						}else{
							reject(e);
						}
					 }
				});
				ssm.show();
			})
			//#endif
			
            // 适应H5
			//#ifdef H5
				var promise=uni.showModal({
					title: op.title,
					content: op.content,
					showCancel: !op.delCancel,
					cancelText: op.cancelVal,
					confirmText: op.confirmVal,
				});
				
				return new Promise((resolve,reject)=>{
					promise.then(res=>{
						if(res.confirm){
							resolve()
						}else{
							reject();
						}
					})
				})
				
			//#endif
            
		}
        // $showModal挂载到uni对象上
        uni.$showModal = show_modal_fun
        Vue.config.globalProperties.$showModal = show_modal_fun
	}
};
 
export default showModal;